<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理后台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="/favicon.ico" type="image/x-icon" rel="shortcut icon" />
    <!-- Bootstrap 3.3.4 -->
    <link href="/public/admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/public/admin/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="/public/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/public/admin/css/animate.css" rel="stylesheet">
    <link href="/public/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/public/admin/css/style.css?v=4.0.0" rel="stylesheet">
    <link href="/public/admin/css/ratuo.css" rel="stylesheet">
    <!-- jQuery 2.1.4 -->
    <script src="/public/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/admin/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="/public/admin/js/myFormValidate.js"></script>
    <script src="/public/admin/js/common.js"></script>
    <script src="/public/admin/js/myAjax.js"></script>
    <script src="/public/admin/js/plugins/layer/layer.min.js"></script>
    <script src="/public/admin/js/jquery.validate.js"></script>

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>管理组列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">
                                    <div class="panel-body">
                                        <a href="javascript:void(0);" onclick="add()" class="btn btn-primary"><i class="fa fa-plus"></i>添加管理组</a>
                                        <a onclick="window.location.href=location.href;" href="javascript:;" class="btn btn-primary pull-right"><i class="glyphicon glyphicon-refresh"></i>刷新</a>
                                    </div>                  
                                </div>
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <table id="list-table" class="table table-bordered">
                                                <thead>
                                                    <tr role="row" >
                                                        <th>ID</th>
                                                        <th>用户组名</th>
                                                        <th>是否超级管理员</th>
                                                        <th>操作</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    {foreach name="data" item="v"}
                                                    <tr role="row" >
                                                        <td>{$v['id']}</td>
                                                        <td>{$v['title']}</td>
                                                        <td>
                                                            <img width="20"  height="20" class="cursor" src="/public/admin/images/{if $v['level'] == 1}yes.png{else /}cancel.png{/if}" onclick="changeTableVal('authGroup','id','{$v.id}','level',this)"/>
                                                        </td>
                                                        <td>
                                                            <a href="javascript:;" onclick="openLayer('{:url("Admin/Rule/ruleGroup",array('id'=>$v['id'] ))}','分配权限')" >分配权限</a> |
                                                            <a href="javascript:;" ruleId="{$v['id']}" ruleName="{$v['name']}" ruleTitle="{$v['title']}" onclick="edit(this)">修改</a> |
                                                            <a href="javascript:;" onclick="del('{$v.id}')">删除</a>
                                                        </td>
                                                    </tr>
                                                    {/foreach}
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加管理组</h4>
            </div>
            <div class="modal-body">
                <form id="bjy-form" class="form-horizontal" action="{:url('Admin/Rule/groupForm')}" method="post">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">管理组名：</label>
                        <div class="col-sm-7">
                            <input class="configInput form-control" name="title" type="text" required="" aria-required="true">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-3 col-sm-offset-3">
                            <button class="btn btn-primary" type="submit">添加</button>
                        </div>
                    </div> 
                </form>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改管理组名</h4>
            </div>
            <div class="modal-body">
                <form id="bjy-form" class="form-horizontal" action="{:url('Admin/Rule/groupForm')}" method="post">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">管理组名：</label>
                        <div class="col-sm-7">
                            <input class="configInput form-control" name="title" type="text" required="" aria-required="true">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-3 col-sm-offset-3">
                            <button class="btn btn-primary" type="submit">修改</button>
                        </div>
                    </div> 
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    function openLayer(url,name){
        parent.layer.open({
            type: 2,
            title: name,
            shade: 0.5,
            shadeClose : false,
            maxmin: true,   //开启最大化最小化按钮
            area: ['80%', '90%'],
            content: url,
            end : function(){
                var handle_status = $("#handle_status").val();
                if(handle_status == '1'){
                    window.location.href = location.href;
                }
            }
        });
    }

    // 添加菜单
    function add(){
        $("input[name='title']").val('');
        $('#bjy-add').modal('show');
    }

    // 修改菜单
    function edit(obj){
        var ruleId  = $(obj).attr('ruleId');
        var ruletitle=$(obj).attr('ruletitle');
        $("input[name='id']").val(ruleId);
        $("input[name='title']").val(ruletitle);
        $('#bjy-edit').modal('show');
    }

    function del(id) {
        parent.layer.confirm('确定要删除?', function(){
            parent.layer.closeAll('dialog');
            $.ajax({
                url:"/index.php/Admin/Rule/groupDel/id/"+id,
                success: function(v){
                    var v =  eval('('+v+')');
                    parent.layer.msg(v.msg, {icon: 1,time: 1000});
                    // if(v.hasOwnProperty('status') && (v.status == 1))
                    //     window.location.href = location.href;
                }
            });
            return false;
        });
    }
</script>


</body>
</html>